import Data.List
import Data.Array
import Data.Ord	

primes :: [Integer]
primes = 2 : filter ( (==1) . length . primeFactors ) [3,5..]

primeFactors :: Integer -> [Integer]
primeFactors n = factor n primes
	where
	factor n (p:ps)
		| p*p > n		 = [n]
		| n `mod` p == 0 = p : factor ( n `div` p )	(p:ps)
		| otherwise		 = factor n ps

quadratic :: (Integer,Integer) -> Integer -> Integer
quadratic (a,b) n = n*n + a*n + b

isPrime :: Integer -> Bool
isPrime n
	| n <= 1 	= False
	| otherwise =((length(primeFactors n)) == 1)


euler_027 = fst $ maximumBy (comparing snd) [ ( (a*b), length(takeWhile isPrime ([quadratic (a,b) x| x<-[2..]])) )| a <- [-1000..1000], b <- [-1000..1000] ]